﻿using System;
using System.Collections.Generic;
using System.Linq;

using LEEAAttendanceControl.Web;

using System.ComponentModel.DataAnnotations;

namespace LEEAAttendanceControl.Web
{
    public partial class UserLoginValidationAttribute : ValidationAttribute
    {
        AttendanceDBEntities context = new AttendanceDBEntities();

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            string login = value as string;

            ValidationResult result = ValidationResult.Success; ;

            if (context.Users.Where(u => u.Login == login).Count() > 0)
            {
                result = new ValidationResult("Login already exists");
            }

            return result;
        }
    }
}